package com.bdqn.controller;

import com.alibaba.fastjson.JSON;
import com.bdqn.service.ICourseService;
import com.bdqn.utli.CookieUtil;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import sun.plugin.javascript.JSObject;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 忍
 * @title: CourseController
 * @projectName Teaching
 * @description: TODO
 * @date 2019/6/2922:31
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    ICourseService courseService;
    @GetMapping()
    public ModelAndView getCourseById(HttpServletResponse response,
                                      @RequestParam (required = false) Integer directId,
                                      @RequestParam (required = false) Integer typeId,
                                      @RequestParam (required = false) String level,
                                      @RequestParam (required = false) String sort,
                                      @RequestParam (required = false) String unlearn,
                                      @RequestParam (required = false) Integer courseId){
        ModelAndView mav = new ModelAndView();
        mav.addObject("courses",courseService.getCourseByDirectId(directId,typeId,level,sort,unlearn,courseId));
        mav.setViewName("course");
        return mav;
    }
    @GetMapping("/{id}")
    public ModelAndView getCourseById(@PathVariable Integer id){
        ModelAndView mav = new ModelAndView();
        mav.addObject("course",courseService.getCourseById(id));
        mav.setViewName("learn");
        return mav;
    }
    @GetMapping("/mes/{id}")
    public String getCourseMesById(@PathVariable Integer id){
        return JSON.toJSONString(courseService.getCourseMesById(id));
    }
}
